package olegroshka.src.com.bofa.olegroshka.report;

import olegroshka.src.com.bofa.olegroshka.datasource.ReportDataSource;

public class ReportGenerator {

	private final ReportDataSource dataSource;
	private final SimpleReportPrinter reportWriter;

	public ReportGenerator(
			ReportDataSource dataSource,
			SimpleReportPrinter reportWriter) {
		this.dataSource = dataSource;
		this.reportWriter = reportWriter;
	}

	public void generate() {
		dataSource.begin();
		reportWriter.writeHeader(dataSource.getHeaderData());
		for (Object[] record : dataSource) {
			reportWriter.writeData(record);
		}
		dataSource.end();
		reportWriter.writeFooter(dataSource.getTotals());
	}

}
